<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<%
  @active_tab = "settings"
  add_crumb t(:settings_crumb, "Settings")
  js_bundle :account_settings
  css_bundle :account_settings, :reports, :tinymce
  content_for :page_title, t(:page_title, "Account Settings")
  if can_do(@context, @current_user, :manage_storage_quotas)
    js_env :ACCOUNT => {
      'id' => @context.id,
      'default_storage_quota_mb' => @context.default_storage_quota_mb,
      'default_user_storage_quota_mb' => @context.default_user_storage_quota_mb,
      'default_group_storage_quota_mb' => @context.default_group_storage_quota_mb,
      'site_admin' => @account.site_admin?,
      'root_account' => @account.root_account?
    }
  end
%>


<% content_for :right_side do %>
  {{> views/courses_right_side}}
  {{> views/additional_settings_right_side}}
<% end %>
<h1 class='screenreader-only'>{{#t}}Account Settings{{/t}}</h1>
<% content_for :stylesheets do %>
  <style type="text/css" media="screen">
    fieldset {
      margin: 2em 0;
    }
    fieldset.nested {
      margin-top: 0;
      margin-left: 20px;
    }
    legend{
      font-size: 1.1em;
    }
  </style>
<% end %>

<div id="account_settings_tabs" style="display:none;" class="ui-tabs-minimal">
  <ul>
    <% if can_do(@context, @current_user, :manage_account_settings) %>
    <li><a href="#tab-settings" id="tab-settings-link">{{#t}}Settings{{/t}}</a></li>
    <% end %>
    <% if can_do(@context, @current_user, :manage_storage_quotas) %>
    <li><a href="#tab-quotas" id="tab-quotas-link">{{#t}}Quotas{{/t}}</a></li>
    <% end %>
    <% if can_do(@context, @current_user, :manage_account_settings) && @account.root_account? && !@account.site_admin? %>
    <li><a href="#tab-notifications" id="tab-notifications-link">{{#t}}Notifications{{/t}}</a></li>
    <% end %>
    <li><a href="#tab-users" id="tab-users-link">{{#t}}Admins{{/t}}</a></li>
    <li><a href="#tab-announcements" id="tab-announcements-link">{{#t}}Announcements{{/t}}</a></li>
    <% if !@available_reports.blank? %>
      <li><a href="#tab-reports" id="tab-reports-link">{{#t}}Reports{{/t}}</a></li>
    <% end %>
    <% if can_do(@context, @current_user, :read_as_admin) %>
      <li><a href="#tab-tools" id="tab-tools-link">{{#t}}Apps{{/t}}</a></li>
    <% end %>
    <% if @context.root_account.settings[:enable_alerts] && can_do(@context, @current_user, :manage_interaction_alerts) %>
      <li><a href="#tab-alerts" id="tab-alerts-link">{{#t}}Alerts{{/t}}</a></li>
    <% end %>
    <% if can_do(@context, @current_user, :manage_feature_flags) %>
      <li><a href="#tab-features" id="tab-features-link">{{#t}}Feature Options{{/t}}</a></li>
    <% end %>
  </ul>
  <% if can_do(@context, @current_user, :manage_account_settings) %>
    <div id="tab-settings">
      <h2 class="screenreader-only">{{#t}}Account Settings{{/t}}</h2>
      <%= form_for :account, :url => account_url(@account), :html => {:method => :put, :id => "account_settings", :class => 'account_settings'} do |f| %>
        <fieldset id="account_settings">
          <legend>{{#t}}Account Settings{{/t}}</legend>
          <table class="formtable">
            <tr>
              <td><%= f.blabel :name, :en => "Account Name" %></td>
              <td><%= f.text_field :name, :class => 'same-width-as-select' %></td>
            </tr>
            <% if !@account.root_account? && (@context.sis_source_id && can_do(@context.root_account, @current_user, :read_sis) || can_do(@context.root_account, @current_user, :manage_sis)) %>
              <tr>
                <td><%= f.blabel :sis_source_id, :en => "SIS ID" %></td>
                <td>
                  <span class="course_form">
                    <% if can_do(@context.root_account, @current_user, :manage_sis) %>
                      <%= f.text_field :sis_source_id, :title => "SIS ID", :value => @context.sis_source_id %>
                    <% else %>
                      <span class="sis_source_id"><%= @context.sis_source_id %></span>
                    <% end %>
                  </span>
                </td>
              </tr>
            <% end %>
            <% if available_locales.size > 1 %>
            <tr>
              <td><%= f.blabel :default_locale, :default_language, :en => "Default Language" %></td>
              <td>
                <% no_language = t(:no_language_preference, "Not set (defaults to %{language})", :language => available_locales[infer_locale(:context => @context.parent_account)]) %>
                <%= f.select :default_locale,
                             [[no_language, nil]] + available_locales.invert.sort_by { |desc, _| Canvas::ICU.collation_key(desc) },
                             {:selected => @context.default_locale}, {:class => 'locale'} %>
                {{> views/shared/locale_warning}}
                <p class="unbreakable"><%= mt :transifex_message, <<-TEXT, :transifex_url => "https://www.transifex.com/instructure/canvas-crowdsource/"
Join the [Canvas Translation Community](%{transifex_url})
TEXT
                %>
                </p>
                <p style="font-size: 0.9em;">{{#t}}This will override any browser/OS language settings. Preferred languages can still be set at the course/user level.{{/t}}</p>
              </td>
            </tr>
            <% end %>
            <% if @account.root_account? %>
              <tr>
                <td><%= f.blabel :default_time_zone, :en => "Default Time Zone" %></td>
                <td>
                  <%= f.time_zone_select :default_time_zone, I18nTimeZone.us_zones, :model => I18nTimeZone %>
                </td>
              </tr>
              <%= f.fields_for :settings do |settings| %>
                <% if @account.grants_right?(@current_user, :manage_site_settings) %>
                  <tr>
                    <td><%= settings.blabel :mfa_settings, :en => "Multi-Factor Authentication" %></td>
                    <td><%= settings.select :mfa_settings, [[t('select.mfa.disabled', "Disabled"), :disabled],
                                                            [t('select.mfa.optional', "Optional"), :optional],
                                                            [t('select.mfa.required_for_admins', "Required for Admins"), :required_for_admins],
                                                            [t('select.mfa.required', "Required"), :required]], :selected => @account.mfa_settings %>
                    </td>
                  </tr>
                <% end %>
                <% unless @account.site_admin? %>
                  <tr>
                    <td><%= settings.blabel :self_enrollment, :en => "Allow Self-Enrollment" %></td>
                    <td>
                      <%= settings.select :self_enrollment, [
                              [t(:never_allow_self_enrollment_option, 'Never'), ''],
                              [t(:self_enroll_for_manually_created_courses_option, 'For Manually-Created Courses'), 'manually_created'],
                              [t(:self_enroll_for_any_courses_option, 'For Any Courses'), 'any']
                        ], :selected => @account.settings[:self_enrollment] %>
                    </td>
                  </tr>

                  <% unless @account.non_canvas_auth_configured?
                    # if the account has a account_authorization_config,
                    # we'll control this setting from that page
                  %>
                    <tr>
                      <td>
                        <%= settings.blabel :login_handle_name, en: "Login Label" %>
                      </td>
                      <td>
                        <%= settings.text_field :login_handle_name,
                                                value: @account.login_handle_name,
                                                class: 'same-width-as-select',
                                                placeholder: t(:login_handle_name_placeholder, "ex: Login, Username, or Student ID") %>
                      </td>
                    </tr>
                  <% end %>

                  <tr>
                    <td><%= settings.blabel :trusted_referers, :en => "Trusted HTTP Referers" %></td>
                    <td>
                      <%= settings.text_field :trusted_referers,
                                              :value => @account.settings[:trusted_referers],
                                              :class => 'same-width-as-select',
                                              :placeholder => "https://example.edu" %>
                      <p style="font-size: 0.9em;">{{#t}}This is a comma separated list of URL's to trust.  Trusting any URL's in this list will bypass the CSRF token when logging in to Canvas.{{/t}}</p>
                    </td>
                  </tr>

                  <tr>
                    <td colspan="2"><%= settings.check_box :prevent_course_renaming_by_teachers, :checked => @account.settings[:prevent_course_renaming_by_teachers] %>
                    <%= settings.label :prevent_course_renaming_by_teachers, :en => "Don't let teachers rename their courses" %>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2"><%= settings.check_box :allow_sending_scores_in_emails, :checked => @account.settings[:allow_sending_scores_in_emails] != false %>
                    <%= settings.label :allow_sending_scores_in_emails, :en => "Students can opt-in to receiving scores in email notifications" %>
                    </td>
                  </tr>
                  <% if @account.grants_right?(@current_user, :manage_site_settings) %>
                    <tr>
                      <td colspan="2"><%= settings.check_box :include_students_in_global_survey, checked: @account.include_students_in_global_survey?%>
                        <%= settings.label :include_students_in_global_survey, en: "Include students in global surveys" %>
                      </td>
                    </tr>
                  <% end %>
                  <tr>
                    <td colspan="2"><%= settings.check_box :restrict_quiz_questions, :checked => @account.settings[:restrict_quiz_questions] %>
                      <%= settings.label :restrict_quiz_questions, :en => "Restrict students from viewing quiz questions after course end date" %>
                    </td>
                  </tr>
                <% end %>
              <% end %>
            <% end %>
            <% unless @account.site_admin? %>
              <%= f.fields_for :settings do |settings| %>
                <%= settings.fields_for :restrict_student_future_view do |r| %>
                  <% hash = @account.restrict_student_future_view %>
                  <% disabled = hash[:locked] && hash[:inherited] %>
                  <tr>
                    <td colspan="2"><%= r.check_box :value, :checked => hash[:value], :disabled => disabled %>
                      <%= r.label :value , t("Restrict students from accessing courses before start date") %>
                    </td>
                  </tr>
                  <% unless disabled %>
                    <tr>
                      <td colspan="2" class="sub_checkbox">
                        <%= r.check_box :locked, :checked => hash[:locked] %>
                        <%= r.label :locked, :en => "Lock this setting for sub-accounts and courses" %>
                      </td>
                    </tr>
                  <% end %>
                <% end %>

                <%= settings.fields_for :restrict_student_future_listing do |r| %>
                  <% hash = @account.restrict_student_future_listing %>
                  <% disabled = hash[:locked] && hash[:inherited] %>
                  <tr class="future_listing">
                    <td colspan="2"><%= r.check_box :value, :checked => hash[:value], :disabled => disabled %>
                      <%= r.label :restrict_student_future_listing, :en => "Restrict students from viewing future courses in enrollments list" %>
                    </td>
                  </tr>
                  <% unless disabled %>
                    <tr class="future_listing">
                      <td colspan="2" class="sub_checkbox">
                        <%= r.check_box :locked, :checked => hash[:locked] %>
                        <%= r.label :locked, t("Lock this setting for sub-accounts") %>
                      </td>
                    </tr>
                  <% end %>
                <% end %>

                <%= settings.fields_for :restrict_student_past_view do |r| %>
                  <% hash = @account.restrict_student_past_view %>
                  <% disabled = hash[:locked] && hash[:inherited] %>
                  <tr>
                    <td colspan="2"><%= r.check_box :value, :checked => hash[:value], :disabled => disabled %>
                      <%= r.label :value, t("Restrict students from accessing courses after end date") %>
                    </td>
                  </tr>
                  <% unless disabled %>
                    <tr>
                      <td colspan="2" class="sub_checkbox">
                        <%= r.check_box :locked, :checked => hash[:locked] %>
                        <%= r.label :locked, :en => "Lock this setting for sub-accounts and courses" %>
                      </td>
                    </tr>
                  <% end %>
                <% end %>

                <%= settings.fields_for :lock_all_announcements do |r| %>
                  <% hash = @account.lock_all_announcements %>
                  <% disabled = hash[:locked] && hash[:inherited] %>
                  <tr>
                    <td colspan="2"><%= r.check_box :value, :checked => hash[:value], :disabled => disabled %>
                      <%= r.label :value, :en => "Disable comments on announcements" %>
                    </td>
                  </tr>
                  <% unless disabled %>
                    <tr>
                      <td colspan="2" class="sub_checkbox">
                        <%= r.check_box :locked, :checked => hash[:locked] %>
                        <%= r.label :locked, :en => "Lock this setting for sub-accounts and courses" %>
                      </td>
                    </tr>
                  <% end %>
                <% end %>

                <%= settings.fields_for :enable_offline_web_export do |r| %>
                  <% hash = @account.enable_offline_web_export %>
                  <% disabled = hash[:locked] && hash[:inherited] %>
                  <tr>
                    <td colspan="2">
                      <%= r.check_box :value, checked: hash[:value], disabled: disabled %>
                      <%= r.label :value, t("Allow students to download course content and view offline") %>
                    </td>
                  </tr>
                <% end %>
              <% end %>
            <% end %>
          </table>
        </fieldset>

        <%= render partial: 'additional_settings', locals: { f: f } %>

        <% if !@account.site_admin? && @account.root_account? && @account.grants_right?(@current_user, :manage_site_settings) %>
          <% TermsOfService.ensure_terms_for_account(@account) %>
          <% js_env(:TERMS_OF_SERVICE_CUSTOM_CONTENT => @account.terms_of_service_content&.content) %>
          <% js_bundle :terms_of_service_modal%>
          <fieldset>
            <legend>{{#t}}Terms of Service{{/t}}</legend>
            <%= f.fields_for :terms_of_service do |tos| %>
              <%= tos.label :terms_type, t("License Type") %>
              <%= tos.select :terms_type, options_for_select(TermsOfService.type_dropdown_options, @account.terms_of_service.terms_type) %>
              <br>
              <%= tos.check_box :passive, :checked => @account.terms_of_service.passive %>
              <%= tos.label :passive, t("Allow passive acceptance of Terms of Service")%>
            <% end %>
          </fieldset>
          <div id="custom_tos_rce_container" style="<%= hidden %>">
            <textarea name="account[terms_of_service][content]"></textarea>
          </div>
          <div id="terms_of_service_preview_link"></div>
        <% end %>
        <% if !@account.site_admin? &&
               @account.root_account? &&
               @account.feature_enabled?(:google_docs_domain_restriction) &&
               @account.grants_right?(@current_user, :manage_site_settings) %>
          <fieldset id="google-docs-domain">
            <legend>{{#t}}Allowed Google Docs Domain{{/t}}</legend>

            <%= f.fields_for :settings do |settings| %>
              <%= settings.label      :google_docs_domain, t('labels.domain', 'Domain:') %>
              <%= settings.text_field :google_docs_domain, placeholder: 'gmail.com', value: @account.settings[:google_docs_domain] %>
            <% end %>
          </fieldset>
        <% end %>

        <% unless @account.site_admin? %>
          <fieldset>
            <h2 class="screenreader-only">{{#t}}Quiz IP Address Filters{{/t}}</h2>
            <legend>{{#t}}Quiz IP Address Filters{{/t}}
              <button class='Button Button--icon-action ip_help_link' type='button'>
                <i class='icon-question'></i>
                <span class='screenreader-only'>{{#t}}What are Quiz IP Filters?{{/t}}</span>
              </button>
            </legend>

            <div id="ip_filters_dialog" style="display: none;">
              <h2>{{#t}}What are Quiz IP Filters?{{/t}}</h2>
              <%= mt(:quiz_ip_filters_help_message,
              "Quiz IP filters are a way to limit access to quizzes to computers in a specified IP range.\n\n" +

              "Specify a set of IP address filters that teachers can use to " +
              "protect access to quizzes.  Filters can be a comma-separated " +
              "list of addresses, or an address followed by a mask " +
              "(\"192.168.217.1/24\" or \"192.168.217.1/255.255.255.0\").\"") %>
            </div>
            <table class="formtable">
              <tbody id="ip_filters">
                <% ((@account.settings[:ip_filters] || {}).sort_by(&:first) << [nil, nil]).each do |name, filter| %>
                  <tr class="ip_filter <%= raw ' blank" style="display: none;' if name.nil? %>">
                    <td> <label> {{#t}}Name:") %></label> <input aria-label="<%= t("Name{{/t}}" type="text" class="name" value="<%= name %>"/></td>
                    <td> <label> {{#t}}Filter:") %></label> <input aria-label="<%= t("Filter{{/t}}" type="text" class="value" value="<%= filter %>" maxlength="255"/></td>
                    <td>
                      <a href="#" title="{{#t}}Remove Filter{{/t}}" class="delete_filter_link"><i class="icon-end standalone-icon"></i></a>
                    </td>
                  </tr>
                <% end %>
              </tbody>
            </table>
            <a href="#" class="icon-add add_ip_filter_link">
              <span aria-hidden="true">{{#t}}Filter{{/t}}</span>
              
            </a>
          </fieldset>
        <% end %>

        <fieldset>
          <h2 class="screenreader-only">{{#t}}Features{{/t}}</h2>
          <legend>{{#t}}Features{{/t}}</legend>
          <%= f.fields_for :settings do |settings| %>
            <% if @account.root_account? %>
              <% if @account.grants_right?(@current_user, :manage_site_settings) %>
                <div>
                  <%= settings.check_box :admins_can_change_passwords, :checked => @account.settings[:admins_can_change_passwords] == true %>
                  <%= settings.label :admins_can_change_passwords, :en => "Password setting by admins" %>
                </div>
                <div>
                  <%= settings.check_box :admins_can_view_notifications, :checked => @account.settings[:admins_can_view_notifications] %>
                  <%= settings.label :admins_can_view_notifications, :en => "Admins can view notifications" %>
                </div>
                <div>
                  <%= settings.check_box :canvadocs_prefer_office_online, :checked => @account.settings[:canvadocs_prefer_office_online] %>
                  <%= settings.label :canvadocs_prefer_office_online, :en => "Prefer Office 365 file viewer" %>
                </div>
                <% unless @account.site_admin? %>
                  <div>
                    <%= f.check_box :enable_user_notes, :checked => @account.enable_user_notes %>
                    <%= f.label :enable_user_notes, :en => "Faculty Journal" %>
                  </div>
                  <div>
                    <%= settings.check_box :enable_eportfolios, :checked => @account.settings[:enable_eportfolios] != false %>
                    <%= settings.label :enable_eportfolios, :en => "ePortfolios" %>
                  </div>

                  <% if !@account.feature_enabled?(:new_sis_integrations) %>
                    <div id="old_sis_integrations">
                      <%= f.check_box :allow_sis_import, :checked => @account.allow_sis_import %>
                      <%= f.label :allow_sis_import, t("SIS imports") %>
                    </div>
                  <% end %>

                  <div>
                    <%= settings.check_box :allow_invitation_previews, :checked => @account.settings[:allow_invitation_previews] %>
                    <%= settings.label :allow_invitation_previews, :en => "Invitation Previews" %>
                  </div>
                  <div>
                    <%= settings.check_box :enable_alerts, :checked => @account.settings[:enable_alerts] %>
                    <%= settings.label :enable_alerts, :en => "Alerts (beta)" %>
                  </div>
                <% end %>
                <%# end of site_admin? %>


                <div id="global_includes_warning_message_wrapper">
                  <%= settings.check_box :global_includes, :checked => @account.settings[:global_includes] %>
                  <%= settings.label :global_includes, :en => "Custom CSS/JavaScript overrides" %>
                  <div id="global_includes_warning_message" class="account_settings__help-text">
                    <p>
                      {{#t}}Custom CSS and Javascript may cause accessibility issues or conflicts with future Canvas updates!{{/t}}
                    </p>
                    <p>
                      <%= t do %>
                      Before implementing custom CSS or Javascript, please refer to <a href="https://community.canvaslms.com/docs/DOC-3010" target="_blank"> our documentation</a>.
                      <% end %>
                    </p>
                  </div>
                </div>
                <div id="show_scheduler_checkbox">
                  <%= settings.check_box :show_scheduler, :checked => @account.settings[:show_scheduler] %>
                  <%= settings.label :show_scheduler, :en => "Enable Scheduler" %>
                </div>
                <div>
                  <%= settings.check_box :enable_profiles, :checked => @account.settings[:enable_profiles] %>
                  <%= settings.label :enable_profiles, :en => "Enable Profiles" %>
                </div>
              <% end %>
              <%# end of :manage_site_settings %>


              <div>
                <%= settings.check_box :sub_account_includes, checked: @account.settings[:sub_account_includes] %>
                <%= settings.label :sub_account_includes, :en => "Let sub-accounts use the Theme Editor to customize their own branding" %>
              </div>
              <% if @account.canvas_authentication? %>
                <div>
                  <%= settings.check_box :open_registration, :checked => @account.open_registration? %>
                  <%= settings.label :open_registration, :en => "Open Registration" %>
                  <% if @account.delegated_authentication? %>
                    <legend>
                      <%= link_to(image_tag('warning.png', :alt => ''), '#',
                                  :class => 'open_registration_delegated_warning_link no-hover',
                                  :title => t(:open_registration_delegated_warning_tooltip,
                                  "An External Identity Provider is Enabled"))
                                %>
                    </legend>

                    <div id="open_registration_delegated_warning_dialog" style="display: none;">
                        <%= t(:open_registration_delegated_warning_message,
                        "An external identity provider is enabled, and users created via open registration may not be able to log in unless
                        the external identity provider's login form has a link back to %{url}.", :url => canvas_login_url) %>
                    </div>
                  <% end %>
                </div>
              <% end %>
              <div>
                <%= settings.check_box :users_can_edit_name, :checked => @account.settings[:users_can_edit_name] != false %>
                <%= settings.label :users_can_edit_name, :en => "Users can edit their name" %>
              </div>

              <div>
                <%= settings.check_box :edit_institution_email, :checked => @account.edit_institution_email? %>
                <%= settings.label     :edit_institution_email, :en => "Users can delete their institution-assigned email address" %>
              </div>

              <div>
                <%= settings.check_box :author_email_in_notifications, :checked => @account.author_email_in_notifications? %>
                <%= settings.label     :author_email_in_notifications, :en => "Show the email address of sender for user interaction Notifications" %>
              </div>
            <% end %>
            <% unless @account.site_admin? %>
              <div>
                <input type="checkbox" id="enable_equella" <%= 'checked' if !@account.settings[:equella_endpoint].blank? %> />
                <label for="enable_equella"><%= t 'labels.equella', 'Equella' %></label>
              </div>
            <% end %>
            <% if @account.grants_right?(@current_user, :manage_site_settings) %>
              <div>
                <%= settings.check_box :enable_turnitin, :checked => @account.settings[:enable_turnitin] %>
                <%= settings.label :enable_turnitin, :en => "Turnitin" %>
              </div>
            <% end %>
          <% end %>
          <%= f.fields_for :services do |services| %>
            <% Account.services_exposed_to_ui_hash(:setting, @current_user, @account).sort_by { |k,h| Canvas::ICU.collation_key(h[:name]) }.each do |key, service| %>
              <div>
                <%= services.check_box key, :checked => @account.service_enabled?(key) %>
                <%= services.label key, service[:name] + " " %>
              </div>
            <% end %>
          <% end %>
        </fieldset>

        <% unless @account.site_admin? %>
            <% if @account.feature_enabled?(:new_sis_integrations) %>
                <%= render partial: 'sis_integration_settings', locals: { f: f } %>
            <% else %>
                <%= render partial: 'sis_integration_settings_old', locals: { f: f } %>
            <% end %>
        <% end %>

        <% if @account.root_account? && !@account.site_admin? && show_feedback_link? %>
          <div id="custom_help_link_settings"></div>
        <% end %>

        <% unless @account.site_admin? %>
          <fieldset id="enable_equella_settings" style="display: none;">
            <legend>{{#t}}Equella Settings{{/t}}</legend>
            <%= f.fields_for :settings do |settings| %>
              <table class="formtable">
                <tr>
                  <td style="vertical-align: top;"><%= settings.label :equella_endpoint, :en => "Equella Endpoint" %></td>
                  <td>
                    <%= settings.text_field :equella_endpoint, :value => @account.settings[:equella_endpoint] %>
                    <div style="font-size: 0.9em;">{{#t}}This is the URL to your equella service.  It will probably look something like \"%{sample_url}\".", :sample_url => "http://oer.equella.com/signon.do{{/t}}</div>
                  </td>
                </tr>
                <tr>
                  <td><%= settings.blabel :equella_teaser, :en => "Equella Comments" %></td>
                  <td><%= settings.text_area :equella_teaser, :style => "width: 90%; height: 75px;", :value => @account.settings[:equella_teaser] %></td>
                </tr>
              </table>
            <% end %>
          </fieldset>

          <% if @account.feature_enabled?(:plagiarism_detection_platform) || @account.settings[:enable_turnitin] %>
            <fieldset id="turnitin_settings">
              <legend>{{#t}}Similarity Detection Platform{{/t}}</legend>
              <table class="formtable">
                <tr>
                  <td><%= f.blabel :turnitin_pledge, en: "Similarity Pledge" %></td>
                  <td>
                    <span style="font-size: 0.9em;">
                      {{#t}}students must check a box acknowledging that they agree with this pledge{{/t}}
                    </span>
                    <%= f.text_area :turnitin_pledge, :style => "width: 90%; height: 50px;" %>
                  </td>
                </tr>
              </table>
            </fieldset>
          <% end %>

          <% if @account.settings[:enable_turnitin] %>
            <fieldset id="turnitin_settings">
              <legend>{{#t}}Turnitin Settings{{/t}}</legend>
              <table class="formtable">
                <tr>
                  <td><%= f.blabel :turnitin_account_id, :en => "Turnitin Account ID" %></td>
                  <td><%= f.text_field :turnitin_account_id, :class => "turnitin_account_settings" %></td>
                </tr>
                <tr>
                  <td><%= f.blabel :turnitin_shared_secret, :en => "Turnitin Shared Secret" %></td>
                  <td><%= f.text_field :turnitin_shared_secret, :class => "turnitin_account_settings" %></td>
                </tr>
                <tr>
                  <td><%= f.blabel :turnitin_host, :en => "Turnitin Host" %></td>
                  <td><%= f.text_field :turnitin_host, :class => "turnitin_account_settings", :placeholder => "api.turnitin.com" %></td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>
                    <a href="<%= account_turnitin_confirmation_path(@account) %>" class="confirm_turnitin_settings_link Button">
                      {{#t}}confirm Turnitin settings{{/t}}
                    </a>
                  </td>
                </tr>
                <tr>
                  <td><%= f.blabel :turnitin_comments, :en => "Submission Comments" %></td>
                  <td>
                    <span style="font-size: 0.9em;">{{#t}}these comments will be shown to students when submitting a Turnitin-enabled assignment{{/t}}</span>
                    <%= f.text_area :turnitin_comments, :style => "width: 90%; height: 50px;" %>
                  </td>
                </tr>
                <tr>
                  <td><%= f.blabel :originality_report_visibility, :en => "Students can see the originality report" %></td>
                  <td>
                    <%= f.select :turnitin_originality, options_for_select(turnitin_originality_options, @account.turnitin_originality)%>
                  </td>
                </tr>
              </table>
            </fieldset>
          <% end %>
        <% end %>

        <% if @account.root_account? and not (exposed_services = Account.services_exposed_to_ui_hash(:service, @current_user)).empty? %>
          <fieldset>
            <h2 class="screenreader-only">{{#t}}Enabled Web Services{{/t}}</h2>
            <legend>{{#t}}Enabled Web Services{{/t}}</legend>
            <%= f.fields_for :services do |services| %>
              <% exposed_services.sort_by { |k,h| Canvas::ICU.collation_key(h[:name]) }.each do |key, service| %>
                <div>
                  <%= services.check_box key, :checked => @account.service_enabled?(key) %>
                  <%= services.label key, service[:name] + " " %>
                </div>
              <% end %>
            <% end %>
            <div style="display:none;">
              <!-- put all of the helpful dialogs describing what each service does in here
                   the magic is in giving it an id of "<name_of_service>_help_dialog" and class="service_help_dialog" -->
              <div class="service_help_dialog" title="{{#t}}About Google Docs Previews{{/t}}" id="google_docs_previews_help_dialog">
                <%= mt(:about_google_docs, <<-TEXT, :terms_url => "https://docs.google.com/viewer/TOS")
Google Docs Previews allow users to view documents from
within Canvas, rather than having to download them and
open the corresponding program (e.g. Word or Excel).

Google Docs Previews can also render file types
not supported by the Canvas document previewer.

By using this service you
acknowledge that you have read and agreed to the
[Google Docs Viewer Terms of Service](%{terms_url}).
                  TEXT
                %>
              </div>
            </div>
          </fieldset>
        <% end %>

        <% if @account.root_account? && !@account.site_admin? %>
          <fieldset>
            <h2 class="screenreader-only">{{#t}}Who Can Create New Courses{{/t}}</h2>
            <legend>{{#t}}Who Can Create New Courses{{/t}}</legend>
            <div style="font-size: 0.8em;">{{#t}}(Account Administrators can always create courses){{/t}}</div>
            <%= f.fields_for :settings do |settings| %>
              <div>
                <%= settings.check_box :teachers_can_create_courses, :checked => @account.teachers_can_create_courses? %>
                <%= settings.label :teachers_can_create_courses, :en => "Teachers" %>
              </div>
              <div>
                <%= settings.check_box :no_enrollments_can_create_courses, :checked => @account.no_enrollments_can_create_courses? %>
                <%= settings.label :no_enrollments_can_create_courses, :en => "Users with no enrollments" %>
              </div>
              <div>
                <%= settings.check_box :students_can_create_courses, :checked => @account.students_can_create_courses? %>
                <%= settings.label :students_can_create_courses, :en => "Students" %>
              </div>
            <% end %>
          </fieldset>
        <% end %>

        <%= render partial: 'external_integration_keys', locals: { f: f } %>

        <div class="button-container">
          <button type="submit" class="Button Button--primary">{{#t}}Update Settings{{/t}}</button>
        </div>
      <% end %>
    </div>
  <% end %>

  <% if can_do(@context, @current_user, :manage_storage_quotas) %>
    <div id="tab-quotas">
      <h2 class="screenreader-only">{{#t}}Account Quotas{{/t}}</h2>
    </div>
  <% end %>

  <% if can_do(@context, @current_user, :manage_account_settings) && @account.root_account? && !@account.site_admin? %>
    <div id="tab-notifications">
      <%= form_for :account, :url => account_url(@account), :html => {:method => :put, :id => "account_settings_notifications"} do |f| %>
        <h2>{{#t}}E-mail Notification "From" Settings{{/t}}</h2>
        <p>{{#t}}This setting allows the Admin to brand or label the 'From' text on all notifications sent from Canvas for this Account.{{/t}}</p>
        <%= f.fields_for :settings do |settings| %>
          <div>
            <%= settings.radio_button :outgoing_email_default_name_option, 'default',
                                      :checked => @account.settings[:outgoing_email_default_name].blank?,
                                      :class => 'notification_from_name_option' %>
            <%= settings.label :outgoing_email_default_name_option_default, :en => "Default Canvas Setting" %>
          </div>
          <div style='padding-left: 2em;'>
            <strong><%= t 'notifications.example', 'Example:' %></strong>
            <blockquote>
              <table class="formtable" style='margin-left: 1.5em;'>
              <tr>
                <td><%= t 'notifications.from', 'From' %></td>
                <td><%= HostUrl.outgoing_email_default_name %> <%= '<notifications@instructure.com>' %></td>
              </tr>
              <tr>
                <td><%= t 'notifications.subject', 'Subject' %></td>
                <td><%= t 'notifications.sample_subject', 'Recent Canvas Notifications' %></td>
              </tr>
              <tr>
                <td><%= t 'notifications.email_date', 'Date' %></td>
                <td><%= datetime_string(Time.zone.now) %></td>
              </tr>
              <tr>
                <td><%= t 'notifications.email_to', 'To' %></td>
                <td><%= 'recipient@instructure.com' %></td>
              </tr>
              <tr>
                <td><%= t 'notifications.email_reply_to', 'Reply-To' %></td>
                <td><%= 'notifications+e79df3ljk09s3jkl09ssljk3lkj2l-10191633@instructure.com' %></td>
              </tr>
            </table>
            </blockquote>
          </div>
          <div>
            <%= settings.radio_button :outgoing_email_default_name_option, 'custom',
                                      :checked => !@account.settings[:outgoing_email_default_name].blank?,
                                      :class => 'notification_from_name_option' %>
            <%= settings.label :outgoing_email_default_name_option_custom, :en => 'Custom "From" Name' %>
          </div>
          <div style='padding-left: 2em;'>
            <p>
              {{#t}}If selected, this will replace all other branding sent in Canvas notifications.{{/t}}
              <br/>
              <%= text_field_tag 'account[settings][outgoing_email_default_name]', @account.settings[:outgoing_email_default_name] %>
            </p>
          </div>
          <div style='padding-left: 2em;'>
            <strong><%= t 'notifications.example', 'Example:' %></strong>
            <blockquote>
            <table class="formtable" style='margin-left: 1.5em;'>
              <tr>
                <td><%= t 'notifications.from', 'From' %></td>
                <td><strong id='custom_default_name_display'></strong> <%= '<notifications@instructure.com>' %></td>
              </tr>
              <tr>
                <td><%= t 'notifications.subject', 'Subject' %></td>
                <td><%= t 'notifications.sample_subject', 'Recent Canvas Notifications' %></td>
              </tr>
              <tr>
                <td><%= t 'notifications.email_date', 'Date' %></td>
                <td><%= datetime_string(Time.zone.now) %></td>
              </tr>
              <tr>
                <td><%= t 'notifications.email_to', 'To' %></td>
                <td><%= 'recipient@instructure.com' %></td>
              </tr>
              <tr>
                <td><%= t 'notifications.email_reply_to', 'Reply-To' %></td>
                <td><%= 'notifications+e79df3ljk09s3jkl09ssljk3lkj2l-10191633@instructure.com' %></td>
              </tr>
            </table>
            </blockquote>
          </div>

          <h2>{{#t}}Notifications Sent to External Services{{/t}}</h2>
          <table class="formtable">
            <tr>
              <td><input type="checkbox" id="account_settings_external_notification_warning_checkbox" <%= 'checked="checked"' if @account.settings[:external_notification_warning] %> /></td>
              <td>
                <label for="account_settings_external_notification_warning_checkbox">{{#t}}Display one time pop-up warning on Notification Preferences page.{{/t}}</label>
                <input type="hidden" name="account[settings][external_notification_warning]" id="account_settings_external_notification_warning" value="<%= @account.settings[:external_notification_warning] ? 1 : 0 %>" />
              </td>
            </tr>
          </table>

          <table style="margin-left: 1.5em;" cellspacing="0" class="formtable">
            <tr>
              <td>
                <b>{{#t}}Pop-up Message Content:{{/t}}</b>
                <blockquote>{{#t}}Notice: Some notifications may contain confidential information. Selecting to receive notifications at an email other than your institution provided address may result in sending sensitive Canvas course and group information outside of the institutional system.{{/t}}</blockquote>
              </td>
            </tr>
          </table>

        <% end %>

        <div class="button-container">
          <button type="submit" class="Button Button--primary">{{#t}}Update Settings{{/t}}</button>
        </div>
      <% end %>
    </div>
  <% end %>

  <div id="tab-users">
    <h2>{{#t}}Account Admins{{/t}}</h2>
    <ul class="admins_list user_list list admins">
      {{> views/account_user}}
      <% available_roles = @context.available_account_roles(false, @current_user) %>
      <% unless available_roles.empty? %>
        {{> views/account_user}}
      <% end %>
    </ul>
    <% unless available_roles.empty? %>
      <% js_bundle :user_lists %>
      <a href="#" class="add_users_link Button Button--primary" title="{{#t}}Add Account Admins') %>" aria-label="{{#t}}Account Admins{{/t}}</a>
      <%= form_tag account_add_account_user_url(@account), {:id => "enroll_users_form", :style => "display: none;"} do  %>
        <h2>{{#t}}Add Account Admins{{/t}}</h2>
        <div style="margin-top: 5px;">
          <div>
            <%= label_tag :role_id, t("Add More") %>
            <select name="role_id" id="admin_role_id">
            <% available_roles.each do |role| %>
              <option value="<%= role.id %>"><%= AccountUser.readable_type(role.name) %></option>
            <% end %>
            </select>
          </div>
          {{> views/shared/user_lists}}
        </div>
        <div class="form-actions">
          <button type="button" class="Button go_back_button">{{#t}}Go back and edit the list of users{{/t}}</button>
          <button type="button" class="Button cancel_button">{{#t}}Cancel{{/t}}</button>
          <button type="button" class="Button Button---primary verify_syntax_button">{{#t}}Continue...{{/t}}</button>
          <button type="submit" class="Button Button--primary add_users_button">{{#t}}OK Looks Good, Add These Users{{/t}}</button>

        </div>
      <% end %>
    <% end %>
  </div>

  <div id="tab-announcements">
    <h2>{{#t}}Global Announcements{{/t}}</h2>
    <ul class="announcements_list unstyled_list">
      <%= will_paginate(@announcements, params: {anchor: "tab-announcements"}) %>
      <% @announcements.each do |announcement| %>

        <li class="announcements_list_item">
          <div class="ic-notification ic-notification--admin-created ic-notification--<%= notification_container_classname(announcement) %>">
            <div class="ic-notification__icon" role="presentation">
              <i class="<%= notification_icon_classname(announcement) %>"></i>
              <span class="screenreader-only">
                <%= accessible_message_icon_text(notification_icon_type(announcement)) %>
              </span>
            </div>

            <div class="notification_account_content">
              <div class="ic-notification__content">
                <div class="ic-notification__message">
                  <h4 class="ic-notification__title notification_subject">
                    <%= announcement.subject %>
                  </h4>
                  <span class="notification_message">
                    <%= user_content(announcement.message) %>
                  </span>
                  <% if can_do(@account, @current_user, :manage_alerts) %>
                    <div class="ic-notification__admin-actions">
                      <button
                        id="<%= "notification_edit_#{announcement.id}" %>"
                        class="Button Button--icon-action element_toggler edit_notification_toggle_focus"
                        aria-controls="<%= "edit_notification_form_#{announcement.id}" %>"
                        data-edit-toggle-id="<%= announcement.id %>"
                      >
                        
                        <i class="icon-edit"></i>
                      </button>
                      <a href="#" rel="<%= context_url(@account, :context_account_notification_url, announcement) %>" class="Button Button--icon-action delete_notification_link" title="<%= t("Delete announcement %{title}", :title => announcement.subject) %>">
                        
                        <i class="icon-trash"></i>
                      </a>
                    </div>
                  <% end %>
                </div>
              </div>
              <span class="notification_account_content_text">
                <%= t("This is a message for *%{name}*", name: announcement.account.name, wrapper: '<b>\1</b>') %>
              </span>
            </div>

          </div>
          <div class="announcement-details">
            <div class="announcement-details-post-info">
              <div class="announcement-details-post-info__datetime">
                <%= t(:alert_timespan, "from %{start_at} to %{end_at}",
                      :start_at => datetime_string(announcement.start_at),
                      :end_at => datetime_string(announcement.end_at)) %>
              </div>
              <div class="announcement-details-post-info__sender">
                <%= link_to(context_user_name(@account, announcement.user_id), user_path(announcement.user_id)) %>
              </div>
            </div>
            <% if announcement.required_account_service %>
              <div>
                <%= AccountServices.allowable_services[announcement.required_account_service.to_sym].try(:[], :name) %>
              </div>
            <% end %>
            <% unless announcement.account_notification_roles.empty? %>
              <div class="announcement-details-roles">
                <%= t "Send only to the following types of users:" %>
                <%= roles_message(@account) %>
                <ul>
                  <% announcement.account_notification_roles.each do |r| %>
                    <% @course_roles.select {|rt| rt[:id] == r.role_id }.each do |rt| %>
                      <li><%= rt[:label] %></li>
                    <% end %>
                    <% # NilEnrollment is a special case %>
                    <% if r.role_id.nil? %>
                      <li><%= t :no_enrollment_roles, "Unenrolled users" %></li>
                    <% end %>
                    <% @account_roles.select {|rt| rt[:id] == r.role_id }.each do |rt| %>
                      <li><%= rt[:label]  %></li>
                    <% end %>
                  <% end %>
                </ul>
              </div>
            <% end %>
            <% if announcement.months_in_display_cycle %>
              <div>
                <%= t :announcement_sent_to_subset, "Sent to 1 / %{denominator} users each month", denominator: announcement.months_in_display_cycle %>
              </div>
            <% end %>
            <% if can_do(@account, @current_user, :manage_alerts) %>
              <%= render(:partial => "edit_account_notification", :locals => {:announcement => announcement}) %>
            <% end %>
          </div>
        </li>
      <% end %>
    </ul>
    <% if can_do(@account, @current_user, :manage_alerts) %>
      <button id="add_announcement_button" class="Button Button--primary element_toggler add_notification_toggle_focus" aria-controls="add_notification_form" title="{{#t}}Add New Announcement') %>" aria-label="<%= t('Add New Announcement{{/t}}">
        <i class="icon-plus"></i> {{#t}}New Announcement{{/t}}
      </button>
      <%= form_for :account_notification,
       url: account_account_notifications_url(@account),
       html: {
         id: "add_notification_form",
         class: "hidden_form",
         role: "region" } do |f| %>

        <div class="grid-row">

          <div class="col-xs-12 col-lg-6">
            <div class="ic-Form-control">
              <label for="account_notification_subject" class="ic-Label">
                {{#t}}Title{{/t}}
              </label>
              <%= f.text_field :subject, :class => 'ic-Input', :id => 'account_notification_subject' %>
            </div>
          </div>

          <div class="col-xs-12 col-lg-6">
            <div class="ic-Form-control">
              <label for="account_notification_icon" class="ic-Label">
                {{#t}}Announcement type{{/t}}
              </label>
              <select
                id="account_notification_icon"
                class="ic-Input"
                name="account_notification[icon]"
              >
                <%= options_for_select([[t("information"), "information", {:class=>"information"}],
                  [t("error"), "error", {:class=>"error"}],
                  [t("warning"), "warning", {:class=>"warning"}],
                  [t("question"), "question", {:class=>"question"}],
                  [t("calendar"), "calendar", {:class=>"calendar"}]]) %>
              </select>
            </div>
          </div>

        </div>

        <div class="ic-Form-control">
          <label class="ic-Label">{{#t}}Message{{/t}}</label>
          <%= f.text_area :message, :class => 'alert_message' %>
          <% if @account.site_admin? %>
            <p>
              {{#t}}Enter \"{{ACCOUNT_DOMAIN}}\" to substitute the user's root account domain{{/t}}
            </p>
            <p>
              {{#t}}Enter \"{{CANVAS_USER_ID}}\" to substitute the user's unique Canvas ID{{/t}}
            </p>
          <% end %>
        </div>
        <% if @account.site_admin? %>
          <div class="ic-Checkbox-group">
            <div class="ic-Form-control ic-Form-control--checkbox">
              <div id="survey_announcement_field">
                <input type="checkbox" name="account_notification[required_account_service]" id="account_notification_required_account_service" value="account_survey_notifications" />
                <label class="ic-Label" for="account_notification_required_account_service">
                  <%= t "Site Admin Only. Send to 1 / %{denominator} users in enabled accounts each month.", denominator: f.text_field(:months_in_display_cycle, value: AccountNotification.default_months_in_display_cycle, disabled: true) %>
                </label>
              </div>
            </div>
          </div>
        <% end %>
        <div class="ic-Form-control">
          <div class="ic-Label" id="aria-announcements-send-to-group">
            <%= t "Send to" %>
            <%= roles_message(@account) %>
          </div>
          <div class="grid-row">
            <div class="col-xs-12 col-lg-4">
              <i><%= t "Course roles" %></i>
              <div class="ic-Checkbox-group" role="group" aria-labelledby="aria-announcements-send-to-group">
                <% @course_roles.each do |r| %>
                  <div class="ic-Form-control ic-Form-control--checkbox">
                    <%= check_box_tag "account_notification_roles[]", r[:id], false, { :class => "account_notification_role_cbx", :id => "account_notification_role_#{r[:id]}_cbx" } %>
                    <label class="ic-Label" for="<%= "account_notification_role_#{r[:id]}_cbx" %>">
                      <%= r[:label] %>
                      <span class="screenreader-only">
                        <%=t "Send this announcement to users with the course role of %{role}", :role => r[:label] %>
                      </span>
                    </label>
                  </div>
                <% end %>
                <% if @account.root_account? %>
                  <div class="ic-Form-control ic-Form-control--checkbox">
                    <%= check_box_tag "account_notification_roles[]", "NilEnrollment", false, { :class => "account_notification_role_cbx", :id => "account_notification_role_NilEnrollment_cbx" } %>
                    <label class="ic-Label" for="<%= "account_notification_role_NilEnrollment_cbx" %>">
                      <%= t "Unenrolled users" %>
                      <span class="screenreader-only">
                        <%=t "Send this announcement to unenrolled users" %>
                      </span>
                    </label>
                  </div>
                <% end %>
              </div>
            </div>
            <div class="col-xs-12 col-lg-4">
              <i><%= t "Account roles" %></i>
              <div class="ic-Checkbox-group" role="group" aria-labelledby="aria-announcements-send-to-group">
                <% @account_roles.each do |r| %>
                  <div class="ic-Form-control ic-Form-control--checkbox">
                    <%= check_box_tag "account_notification_roles[]", r[:id], false, { :class => "account_notification_role_cbx", :id => "account_notification_role_#{r[:id]}_cbx" } %>
                    <label class="ic-Label" for="<%= "account_notification_role_#{r[:id]}_cbx" %>">
                      <%= r[:label] %>
                      <span class="screenreader-only">
                        <%=t "Send this announcement to users with the account role of %{role}", :role => r[:label] %>
                      </span>
                    </label>
                  </div>
                <% end %>
              </div>
            </div>
          </div>
        </div>

        <div class="grid-row">

          <div class="col-xs-12 col-lg-6">

            <div class="ic-Form-control">
              <label class="ic-Label" id="announcement_starts_at_label">
                {{#t}}Announcement starts at{{/t}}
                <span class="screenreader-only">
                  <%= datepicker_screenreader_prompt %>
                </span>
              </label>
              <%= f.text_field :start_at,
                               :class => 'datetime_field',
                               "aria-labelledby" => "announcement_starts_at_label",
                               "data-tooltip" => "",
                               :title => accessible_date_format %>
            </div>
          </div>

          <div class="col-xs-12 col-lg-6">
            <div class="ic-Form-control">
              <label class="ic-Label" id="announcement_ends_at_label">
                {{#t}}Announcement ends at{{/t}}
                <span class="screenreader-only">
                  <%= datepicker_screenreader_prompt %>
                </span>
              </label>
              <%= f.text_field :end_at,
                               :class => 'datetime_field',
                               "aria-labelledby" => "announcement_ends_at_label",
                               "data-tooltip" => "",
                               :title => accessible_date_format %>
            </div>
          </div>

        </div>

        <div class="ic-Form-actions">
          <button type="Button" class="element_toggler Button Button--secondary add_notification_cancel_focus" aria-controls="add_notification_form">
            {{#t}}Cancel{{/t}}
          </button>
          <button type="submit" class="Button Button--primary">
            {{#t}}Publish announcement{{/t}}
          </button>
        </div>
      <% end %>
    <% end %>
  </div>

  <% if !@available_reports.blank? %>
    <div id="tab-reports">
      <h2 class="screenreader-only">{{#t}}Reports{{/t}}</h2>
      <table class="reports">
        <tr class="reports">
          <th class="reports"><%= t 'headers.report_name', 'Name' %></th>
          <th class="reports"><%= t 'headers.report_last_run', 'Last Run' %></th>
          <th class="reports"></th>
        </tr>
        <% @available_reports.sort_by {|_, details| details.title}.each do |report, details|
           title = details.title
           description_partial = details[:description_partial]
           description_partial = report + '_description' if description_partial == true
           parameters_partial = details[:parameters_partial]
           parameters_partial = report + '_parameters' if parameters_partial == true
           last_complete = @last_complete_reports[report]
           last_report = @last_reports[report]
           in_progress = last_report && last_report.in_progress?
           #the extra text is added so that you can give more than the date for the last run report
           extra_text = last_complete.try(:parameters).try(:[], "extra_text")
        %>
          <tr id="<%= report %>" class="reports">
            <td class="title reports">
              <span class="title"><%= title %></span>
              <% if description_partial %>
                <a href="#" class="open_report_description_link" role="button" aria-haspopup="true" aria-owns="<%= "#{report}_report_description" %>">
                  <i class="icon-question standalone-icon"></i>
                  
                </a>
                <div id="<%= "#{report}_report_description" %>" style="display: none" class="report_description">
                  <%= render(:partial => description_partial) %>
                </div>
              <% end %>
            </td>
            <td class="last-run reports">
              <% if last_complete %>
                <%= datetime_string(last_complete.created_at) %>
                <%#the extra text is added so that you can give more than the date for the last run report %>
                <% if extra_text %>
                  (<%= extra_text %>)
                <% end %>
                <% if last_complete.workflow_state == 'complete' %>
                  <%= link_to "<i class='icon-download'></i>".html_safe, context_url(last_complete.account, :context_file_download_url, last_complete.attachment.id), 'aria-label' => t('Download Report'), 'title' => t('Download Report') %>
                <% end %>
              <% else %>
                <%= t 'report_last_run_never', 'Never' %>
              <% end %>
            </td>
            <td class="action reports">
              <% if parameters_partial %>
                <div style="display: none">
                  <div class="report_dialog">
                    <form id="<%= report %>_form" class="run_report_form" action="<%= api_v1_account_create_report_path(@account, report) %>">
                      <div class="report_parameters">
                        <%= render :partial => parameters_partial if parameters_partial %>
                      </div>
                      <br />
                      <a href="#" id="run_<%= report %>" class="Button Button--primary Button--small run_report_link"><%= t 'links.run_report', 'Run Report' %></a>
                    </form>
                  </div>
                </div>
                <span class="running_report_message" style="<%= hidden unless in_progress %>">
                  {{#t}}The report is running.*You\'ll receive an email when it is done.*', :wrapper => '<div>\1</div>{{/t}}
                </span>
                <a href="#" id="configure_<%= report %>" style="<%= hidden if in_progress %>" class="Button Button--small configure_report_link"><%= t 'links.configure_report', 'Configure...' %></a>
              <% else %>
                <form id="<%= report %>_form" class="run_report_form" action="<%= api_v1_account_create_report_path(@account, report) %>">
                  <span class="running_report_message" style="<%= hidden unless in_progress %>">
                    {{#t}}The report is running.*You\'ll receive an email when it is done.*', :wrapper => '<div>\1</div>{{/t}}
                  </span>
                  <a href="#" id="run_<%= report %>" style="<%= hidden if in_progress %>" class="Button Button--small Button--primary run_report_link"><%= t 'links.run_report', 'Run Report' %></a>
                </form>
              <% end %>
            </td>
          </tr>
        <% end %>
      </table>
    </div>
  <% end %>
  <% if can_do(@context, @current_user, :read_as_admin) %>
      <div id="tab-tools">
        {{> views/external_tools/external_tools}}
      </div>
  <% end %>
  <% if @context.root_account.settings[:enable_alerts] && can_do(@context, @current_user, :manage_interaction_alerts) %>
      <div id="tab-alerts">
        <h2>{{#t}}Alerts{{/t}}</h2>
        {{> views/alerts/alerts}}
      </div>
  <% end %>
  <% if can_do(@context, @current_user, :manage_feature_flags) %>
    <div id="tab-features"></div>
  <% end %>
</div>
